// pages/check/staff/add/add.js
Page({

	/**
	 * 页面的初始数据
	 */
	data: {
		Ord: 0,
		shop: 0,
		saoMa: 0,
		serv: 0,
		mobile: '',
		role: '设置角色',
		mang: 0,
		tk: false,
		sta: 'a'
	},

	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad: function(options) {
		console.log(options.Ord == true)
		wx.getStorage({
			key: 'uid',
			success: (e) => {
				if (options.mobile != undefined) {
					this.setData({
						mobile: options.mobile,
						role: options.role,
						Ord: Number(options.Ord),
						shop: Number(options.shop),
						saoMa: Number(options.saoMa),
						serv: Number(options.serv),
						mang: Number(options.mang),
						sta: 1,
						id: Number(options.id)
					})
				}
				this.setData({
					uid: e.data.uid
				})
			}
		})
	},
	tk() {
		this.setData({
			tk: true
		})
	},
	none() {
		this.setData({
			tk: 'false'
		})
	},
	gb(e) {
		this.setData({
			role: e.currentTarget.dataset.id,
			tk: false
		})
	},
	moblie(e) {
		this.setData({
			mobile: e.detail.value
		})
	},
	Ord(e) {
		this.setData({
			Ord: !(this.data.Ord)
		})
	},
	shop(e) {
		this.setData({
			shop: !(this.data.shop)
		})
	},
	saoMa(e) {
		this.setData({
			saoMa: !(this.data.saoMa)
		})
	},
	serv(e) {
		this.setData({
			serv: !(this.data.serv)
		})
	},
	mang(e) {
		this.setData({
			mang: !(this.data.mang)
		})
	},
	sure() {
		if (this.data.mobile != '' && this.data.role != '设置角色') {
			wx.request({
				url: getApp().globalData.chang + 'action=addYuang&uid=' + this.data.uid + '&mobile=' + this.data.mobile +
					'&role=' + this.data.role +
					'&Ord=' + this.data.Ord + '&shop=' + this.data.shop + '&saoMa=' + this.data.saoMa + '&serv=' + this.data.serv +
					'&mang=' + this.data.mang,
				success: (e) => {
					if (e.data.code == 1) {
						console.log(e)
						wx.navigateBack({
							delta: 1
						})
					} else {
						wx.showToast({
							icon: 'none',
							title: e.data.msg
						})
					}
				}
			})
		} else {
			wx.showToast({
				icon: 'none',
				title: '请填写手机号设置员工角色'
			})
		}
	},
	modification() {
		wx.request({
			url: getApp().globalData.chang + 'action=updateYuang&uid=' + this.data.uid + '&mobile=' + this.data.mobile +
				'&role=' + this.data.role +
				'&Ord=' + Number(this.data.Ord) + '&shop=' + Number(this.data.shop) + '&saoMa=' + Number(this.data.saoMa) + '&serv=' + Number(this.data.serv) +
				'&mang=' + Number(this.data.mang)+'&id='+this.data.id,
			success: (e) => { 
				if (e.data.code == 1) {
					wx.navigateBack({
						delta: 1
					})
				} else {
					wx.showToast({
						icon: 'none',
						title: e.data.msg
					})
				}
			}
		})
	},
	dele(){
		wx.request({
			url:getApp().globalData.chang+'action=delYuang&id='+this.data.id,
			success:(e)=>{
				console.log(e)
				if (e.data.code == 1) {
					wx.navigateBack({
						delta: 1
					})
				} else {
					wx.showToast({
						icon: 'none',
						title: e.data.msg
					})
				}
			}
		})
	}
})
